package com.winning.config;

import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Correlation;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.connection.CorrelationData;

/**
 * @Package: com.winning.config
 * @ClassName: CorrelationMessagePostProcessor
 * @Author: lujieni
 * @Description:
 * @Date: 2021-08-31 16:33
 * @Version: 1.0
 */
public class CorrelationMessagePostProcessor implements MessagePostProcessor {

    @Override
    public Message postProcessMessage(Message message) throws AmqpException {
        return message;
    }

    @Override
    public Message postProcessMessage(Message message, Correlation correlation) {
        if (correlation instanceof CorrelationData) {
            message.getMessageProperties().setCorrelationId(((CorrelationData)correlation).getId());
        }
        return message;
    }

}